In [1]:
%load_ext load_style
%load_style talk.css


Read nino3 SSTA time series, Plot and Save the image

In this noteboo, we will finish the following operations

  • read time series data produced bya previous notebook
  • have a quick plot
  • decorate plots
  • save image

1. Load basic libraries


In [2]:
%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt         # to generate plots

2. Load nino3 SSTA series

Please keep in mind that the nino3 SSTA series lies between 1970 and 1999
Recall ex2


In [3]:
npzfile = np.load('data/ssta.nino3.30y.npz')
npzfile.files


Out[3]:
['ssta_series']

In [4]:
ssta_series = npzfile['ssta_series']
ssta_series.shape


Out[4]:
(360L, 1L)

3. Have a quick plot


In [5]:
plt.plot(ssta_series)


Out[5]:
[<matplotlib.lines.Line2D at 0x82f5ba8>]

4. Make it beautiful

4.1 Add Year ticks and grid lines, etc.

More info can be found from https://matplotlib.org/users/pyplot_tutorial.html


In [6]:
fig = plt.figure(figsize=(15, 6))
ax = fig.add_subplot(111)

plt.plot(ssta_series, 'g-', linewidth=2)

plt.xlabel('Years')
plt.ylabel('[$^oC$]')
plt.title('nino3 SSTA 30-year (1970-1999)', fontsize=12)

ax.set_xlim(0,361)
ax.set_ylim(-3.5,3.5)
ax.set_xticklabels(range(1970,2000,1*4))
ax.axhline(0, color='r')

plt.grid(True)
ax.autoscale_view()

plt.savefig('image/ssta_series_30y.png')


4.2 More professional

Just like the image from https://www.esrl.noaa.gov/psd/enso/mei/


In [7]:
fig = plt.figure(figsize=(15, 6))
ax = fig.add_subplot(111)

xtime       = np.linspace(1,360,360)
ssta_series = ssta_series.reshape((360))

ax.plot(xtime, ssta_series, 'black', alpha=1.00, linewidth=2)
ax.fill_between(xtime, 0., ssta_series, ssta_series> 0., color='red', alpha=.75)
ax.fill_between(xtime, 0., ssta_series, ssta_series< 0., color='blue',  alpha=.75)

plt.xlabel('Years')
plt.ylabel('[$^oC$]')
plt.title('nino3 SSTA 30-year (1970-1999)', fontsize=12)

ax.set_xlim(0, 361)
ax.set_ylim(-4, 4)
ax.set_xticklabels(range(1970,2000,1*4))

plt.grid(True)
ax.autoscale_view()


References

http://unidata.github.io/netcdf4-python/

John D. Hunter. Matplotlib: A 2D Graphics Environment, Computing in Science & Engineering, 9, 90-95 (2007), DOI:10.1109/MCSE.2007.55

Stéfan van der Walt, S. Chris Colbert and Gaël Varoquaux. The NumPy Array: A Structure for Efficient Numerical Computation, Computing in Science & Engineering, 13, 22-30 (2011), DOI:10.1109/MCSE.2011.37

Kalnay et al.,The NCEP/NCAR 40-year reanalysis project, Bull. Amer. Meteor. Soc., 77, 437-470, 1996.


In [ ]: